package com.weixiao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.weixiao.handler.YyghException;
import com.weixiao.mapper.HospitalSetMapper;
import com.weixiao.model.hosp.HospitalSet;
import com.weixiao.result.ResultCodeEnum;
import com.weixiao.service.HospitalSetService;
import com.weixiao.utils.ApiAssert;
import com.weixiao.vo.order.SignInfoVo;
import org.springframework.stereotype.Service;

/**
 * author 韩诚
 * date 2022/9/20 10:58
 */
@Service
public class HospitalSetServiceImpl extends ServiceImpl<HospitalSetMapper, HospitalSet> implements HospitalSetService {
    /**
     * 根据传递过来的医院编码，查询数据库的签名
     */
    @Override
    public String getSignKey(String hoscode) {
        QueryWrapper<HospitalSet> wrapper = new QueryWrapper<HospitalSet>()
                .eq("hoscode", hoscode);
        HospitalSet hospitalSet = baseMapper.selectOne(wrapper);
        return hospitalSet.getSignKey();
    }

    /**
     * 获取医院签名信息
     */
    @Override
    public SignInfoVo getSignInfoVo(String hoscode) {
        QueryWrapper<HospitalSet> wrapper = new QueryWrapper<HospitalSet>()
                .eq("hoscode", hoscode);
        HospitalSet hospitalSet = baseMapper.selectOne(wrapper);
        ApiAssert.isNotNull(hospitalSet,ResultCodeEnum.HOSPITAL_OPEN.getMessage());

        SignInfoVo signInfoVo = new SignInfoVo();
        signInfoVo.setApiUrl(hospitalSet.getApiUrl());
        signInfoVo.setSignKey(hospitalSet.getSignKey());
        return signInfoVo;
    }
}